
import util from '@/lib/util.js';
export default {
  props: {
    selectUseable: { type: Boolean, default: false },
    mobile: null //下单账号
  },
  data() {
    return {
      patientInfo: {
        sex: '0',
        birthday: ''
      },
      birthday: '',
      sex:['女','男']
    };
  },
  selectedPatient: {},
  methods: {
    correctAge(e) {
      Number(e.detail.value) < 1 && ((this.birthday = ''), (this.patientInfo.birthday = ''), uni.toast('年龄必须大于0'));
    },
    bindBirthdayInputChange(e) {
      this.patientInfo.birthday = e.detail.value;
      this.birthday = e.detail.value;
      this.patientMd5();
    },
    bindInputChange() {
      this.patientMd5();
    },
    bindPickerChange(e) {
      console.log(e);
      this.patientInfo.sex = e.target.value;
      this.patientMd5();
    },

    patientMd5(init) {
      let { name, sex, birthday, id } = this.patientInfo;
      birthday = birthday || '';
      // birthday = birthday.toString().substring(0, 10);
      const md5 = escape(name + sex + birthday);
      init ? (this.$options.selectedPatient = { md5, name, sex, birthday, id }) : (this.patientInfo.id = this.$options.selectedPatient.md5 === md5 ? id : null);
    },
    navSelect() {
      const that = this;
      uni.navigateTo({
        url: '/pages/common/patientList/patientList?readyOnly=false',
        events: {
          comeBackData(data) {
            data.sex += '';
            that.patientInfo = data;
            that.birthday = data.birthday;
            that.patientMd5(true);
          }
        }
      });
    }
  }
};